package demo;
//枚举，也会生成独立的字节码文件
public enum TestNum {
    RED(0.1,"红色"),GREEN(1.1, "绿色"),
    BLACK(2.1, "黑色"),WIGHT(3.1, "白色");//都是枚举对象
    public String color;
    public double ordinal;
    private TestNum(double ordinal, String color) {//枚举的构造方法默认是私有的
        this.ordinal = ordinal;
        this.color = color;
    }

    public static void main(String[] args) {
        TestNum[] testNum = TestNum.values();//以数组形式返回枚举类型的所有成员
        for (int i = 0; i < testNum.length; i++) {
            System.out.print(testNum[i]+ " "+testNum[i].ordinal());
        }
        System.out.println();
        TestNum testNum1 = TestNum.valueOf("WIGHT");//将普通字符串转换为对应枚举实例
        System.out.println(testNum1);
        System.out.println(WIGHT.compareTo(GREEN));//通过索引进行比较
    }
    public static void main1(String[] args) {
        TestNum testNum = TestNum.BLACK;
        switch (testNum){
            case RED:
                System.out.println("RED");
                break;
            case BLACK:
                System.out.println("BLACK");
                break;
            case GREEN:
                System.out.println("GREEN");
                break;
            default:
                System.out.println("颜色错误");
                break;
        }
    }
}
